﻿using System.Collections.Generic;
using System.Web.Http;
using DefaultConnection;
using MementoWeb.Models;

namespace MementoWeb.Controllers
{
    public class CategoryController : ApiController
    {
        private readonly IDataRepository _dataRepository;

        public CategoryController(IDataRepository dataRepository)
        {
            _dataRepository = dataRepository;
        }

        public IEnumerable<Category> Get()
        {
            return _dataRepository.GetAllCategories();
        }

        public Category GetById(int id)
        {
            return _dataRepository.GetCategoryById(id);
        }

        public void CreateNew(Category category)
        {
            _dataRepository.CreateNewCategory(category);
        }

        public void Update(Category category)
        {
            _dataRepository.SaveCategoryChanges(category);
        }

        public void Delete(int id)
        {
            _dataRepository.DeleteCategory(id);
        }
    }
}
